<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* $Id: flow.php 53 2012-04-03 15:02:56Z zengdong615@gmail.com $
*/
class Flow extends TH_Controller 
{
	var $_uid;

	function __construct()
	{
		parent::__construct();
		$this->load->model(array('flowM'));
		$this->_uid = $this->session->userdata('uid');
	}

	public function insert($type = 0)
	{

		$flow = array('from_id' => $this->_uid,
				'to_id' => $this->_uid,
				'cid' => $type,
				'txt' => $this->input->post('txt'));
		if ($flow['txt']) {
			$this->flowM->add($flow);
		}
	}

	public function flows()
	{
		$rows = $this->flowM->get_all($this->_uid);
		if ($rows) {
			$flows = array();
			$this->load->model('user');
			$begin_id = 0;
			foreach ($rows as $f) {
				$item['time'] = date('Y-m-d H:i:s', $f->create_time);
				$item['id'] = $f->id;
				$item['cid'] = $f->cid;
				$item['txt'] = $this->flowM->get_cnt($f->rid);
				$item['reposts_count'] = 0; //TODO
				$item['user'] = $this->user->get_by_id($f->from_id);
				array_push($flows, $item);
				$begin_id = $f->id;
			}
			$result = array('flows' => $flows,
					'begin_id' => $begin_id);
		}else{
			$result = array('error' => 1,
					'msg' => '没有更多');
		}
		$this->output->set_content_type('application/json');
		$this->output->set_output(json_encode($result));
	}
}